//获取增加、减少按钮
var sub = document.getElementById('sub');
var add = document.getElementById('add');
var actAmount = document.getElementsByClassName('actAmount')[0];
//获取顶部编辑按钮
var topOperationEdit = document.getElementById('topOperationEdit');
var topOperationComplete = document.getElementById('topOperationComplete');

//获取购物车物品数量及编辑购物车数量信息
var amount = document.getElementsByClassName('amount')[0];
var editAmount = document.getElementsByClassName('editAmount')[0];

//获取商品初始化数量
var initAmount = document.getElementById('initAmount');

var checkbox = document.getElementsByClassName('checkbox')[0];
var price = document.getElementsByClassName('price')[0];

var settlementPrice = document.getElementById('settlementPrice');

var selectAll = document.getElementsByClassName('selectAll')[0];

var total = document.getElementById('total');

sub.onclick = function () {
    // alert(actAmount.innerText)
    actAmount.innerText = parseInt(actAmount.innerText) - 1;
    if (parseInt(actAmount.innerText) <= 0) {
        actAmount.innerText = 0
    }
}

add.onclick = function () {
    // alert(actAmount.innerText)
    actAmount.innerText = parseInt(actAmount.innerText) + 1;
    if (parseInt(actAmount.innerText) >= 9) {
        actAmount.innerText = 9
    }
}
//控制顶部编辑按钮编辑数量的显示与隐藏及
topOperationEdit.onclick = function () {
    amount.style.display = 'none'
    editAmount.style.display = 'flex'
    topOperationEdit.style.display = 'none'
    topOperationComplete.style.display = 'inline-block'
}

topOperationComplete.onclick = function () {
    amount.style.display = 'inline-block'
    editAmount.style.display = 'none'
    topOperationEdit.style.display = 'inline-block'
    topOperationComplete.style.display = 'none'
    initAmount.innerText = actAmount.innerText
}

checkbox.checked = true
if (checkbox.checked == true) {
    // console.log(price.innerText)
    // console.log(settlementPrice.innerText)
    // console.log(initAmount.innerText)
    settlementPrice.innerText = parseInt(price.innerText) * parseInt(initAmount.innerText);
    selectAll.checked = true;
} else {
    settlementPrice.innerText = '0.00'
    selectAll.checked = false;
}
checkbox.onclick = function () {
    if (checkbox.checked == true) {
        // console.log(price.innerText)
        // console.log(settlementPrice.innerText)
        // console.log(initAmount.innerText)
        settlementPrice.innerText = parseInt(price.innerText) * parseInt(initAmount.innerText);
        selectAll.checked = true;
    } else {
        settlementPrice.innerText = '0.00'
        selectAll.checked = false;
    }
}

total.onclick = function () {
    alert("一共需要支付: " + settlementPrice.innerText + "元");
}